package com.ys.fmms.compare;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class ListSortExample {
    public static void main(String[] args) {
        // 创建并初始化 List
        List<Person> list = new ArrayList<Person>() {
            {
                add(new Person(1, 30, "北京"));
                add(new Person(2, 20, "西安"));
                add(new Person(3, null, "上海"));
            }
        };
        List<Person> personList = list.stream().sorted(Comparator.comparing(Person::getAge,Comparator.nullsFirst(Integer::compareTo))).collect(Collectors.toList());
        personList.forEach(item-> System.out.println(item));
    }
}
